<template>
  <div class="thirdlogin-form">
    <my-tabs :tab-list="tabList">
      <template v-slot="{ row }">
        <li
          class="item pointer"
          :class="{ active: routePath === row.path }"
          @click="handleClickMenu(row)"
        >
          {{ row.title }}
        </li>
      </template>
    </my-tabs>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="92px" size="mini">
      <el-form-item class="phone" label="手机号">
        {{ phone | formatMask }}
      </el-form-item>
      <el-form-item label="验证码" prop="verify">
        <div class="verify">
          <el-input type="text" v-model="ruleForm.verify" placeholder="请输入验证码">
            <EduVerificationCode
              type="text"
              slot="append"
              @start="handleCode('ruleForm')"
            ></EduVerificationCode>
          </el-input>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleDeleteBind('ruleForm')" :disabled="disabled"
          >确认解绑</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import MyTabs from '../components/myTab.vue'
import EduVerificationCode from '@/components/EduVerificationCode'
export default {
  components: {
    MyTabs,
    EduVerificationCode
  },
  data() {
    return {
      tabList: [
        {
          path: '/my/profile/my_account',
          title: '修改密码'
        },
        {
          path: '/my/profile/payPwd',
          title: '支付密码'
        },
        {
          path: '/my/profile/thirdlogin',
          title: '第三方绑定'
        }
      ],
      rules: {
        verify: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      ruleForm: {
        verify: ''
      },
      phone: this.$store.getters['user/accountInfo'].phone,
      disabled: false
    }
  },
  computed: {
    routePath() {
      return this.$route.path
    }
  },
  methods: {
    // 解绑
    handleDeleteBind(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.disabled = true
          this.$api.deleteConfigThirdloginBind(
            {
              type: this.$route.query.key,
              verify: this.ruleForm.verify
            },
            res => {
              this.$message.success(res.msg)
              this.$router.push({
                path: '/my/profile/thirdlogin'
              })
              this.disabled = false
            },
            err => {
              this.$message.error(err.msg)
              this.disabled = false
            }
          )
        }
      })
    },
    // 获取验证码
    handleCode() {
      this.$api.createSmsVerify(
        {
          phone: this.phone.toString(),
          type: 'unbind_' + this.$route.query.key
        },
        res => {
          this.$message.success(res.msg)
        },
        err => {
          this.$message.error(err.msg)
        }
      )
    },
    handleClickMenu(data) {
      this.$router.push({
        path: data.path
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.thirdlogin-form {
  .phone ::v-deep .el-form-item__content {
    font-size: 13px;
    color: $text-color-auxiliary;
  }
  .verify ::v-deep .el-input {
    width: 224px;
    .el-input-group__append,
    .el-input-group__prepend {
      background: transparent;
      padding: 0 32px;
      border-left: 0;
      @include edu-color-auxiliary;
      .el-button.is-disabled.el-button--text {
        color: $text-color-auxiliary;
      }
    }
  }
}
</style>
